from django.db import models

# Create your models here.
class BaseModel(models.Model):
    create_user=models.CharField(max_length=255,null=True)
    update_user=models.CharField(max_length=255,null=True)
    create_time=models.DateTimeField(null=True)
    update_time=models.DateTimeField(null=True)
    is_delete=models.BooleanField(default=False)
    class Meta():
        abstract=True


class InterfaceUrlModel(BaseModel):
    name=models.CharField(max_length=255,null=True)
    url=models.CharField(max_length=255,null=True)
    class Meta():
        db_table="interfaceurl"


class ResourceModel(BaseModel):
    name = models.CharField(max_length=100)
    pid = models.ForeignKey("self",on_delete=models.CASCADE,null=True)
    url = models.CharField(max_length=255)
    interfaceurl=models.ManyToManyField(InterfaceUrlModel)

    class Meta():
        db_table="resource"




class RoleModel(BaseModel):
    name = models.CharField(max_length=100)
    source = models.ManyToManyField(ResourceModel, related_name="source", null=True)
    class Meta():
        db_table="role"



class UserModel(BaseModel):
    name = models.CharField(max_length=100, null=True)
    phone = models.CharField(max_length=100, null=True)
    pad = models.CharField(max_length=100, null=True)
    role = models.ForeignKey(RoleModel, on_delete=models.CASCADE,null=True)

    class Meta():
        db_table="user"


